<?php
/**
 * Static content controller.
 *
 * This file will render views from views/pages/
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.Controller
 * @since         CakePHP(tm) v 0.2.9
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 */

App::uses('AppController', 'Controller');

/**
 * Static content controller
 *
 * Override this controller by placing a copy in controllers directory of an application
 *
 * @package       app.Controller
 * @link http://book.cakephp.org/2.0/en/controllers/pages-controller.html
 */
class UsersController extends AppController {

/**
 * This controller does not use a model
 *
 * @var array
 */
	public $uses = array('User');

/**
 * Displays a view
 *
 * @param mixed What page to display
 * @return void
 * @throws NotFoundException When the view file could not be found
 *	or MissingViewException in debug mode.
 */
	public function login(){
		$this->layout=false;
		$post_data = $this->data;
		var_dump($post_data);
		if(!empty($this->data)){
			$result = $this->User->validateLogin($this->data);
			$result =true;
			
			if($result !=false){
				echo "he";
				echo "<br> ==> Before Save Session";  
				var_dump($result);       
        $this->Session->write('Person.eyeColor', 'Green');
        //$this->Session->Write('User.username', $this->data['username']); 
         echo "<br> ==> After Save Session";      
				$this->Session->setFlash('Bienvenido '.$result['User']['username'].'!');
				                 
        
       var_dump($this->Session); 
       var_dump($this->Session->Read('dataUser')); 
        try {
				    $this->redirect(array('controller' => 'members', 'action' => 'index', 'home'));
				} catch (Exception $e) {
				    echo 'Excepción capturada: ',  $e->getMessage(), "\n";
				}

			}
		}
	}

	public 	function logout(){
		$this->Session->destroy();
	}
}
